package com.mvp.shq.washer.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.entity.shop.ShopAttr;

import java.util.List;

/**
 * Created by Administrator on 2017/10/10.
 */

public class ShopAttrAdapter extends BaseAdapter {
    private Context context;
    private List<ShopAttr> data;

    public ShopAttrAdapter(Context mContext,List<ShopAttr> list){
        context = mContext;
        data = list;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.item_attr, parent, false);
            holder = new ViewHolder();
            holder.tvAttrName = (TextView) convertView.findViewById(R.id.tv_attr_name);
            holder.imgSelect = (ImageView) convertView.findViewById(R.id.img_select);
            holder.rlContainer = (RelativeLayout) convertView.findViewById(R.id.rl_container);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ShopAttr shopAttr = data.get(position);
        holder.tvAttrName.setText(shopAttr.getAttrName());
        if (shopAttr.isSelect()){
            holder.imgSelect.setVisibility(View.VISIBLE);
            holder.rlContainer.setBackgroundResource(R.drawable.shop_spec_selected_bg);
        }else {
            holder.imgSelect.setVisibility(View.GONE);
            holder.rlContainer.setBackgroundResource(R.drawable.shop_spec_def_bg);
        }
        return convertView;
    }

    private class ViewHolder{
        private TextView tvAttrName;
        private ImageView imgSelect;
        private RelativeLayout rlContainer;
    }
}
